home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13167 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.8 KB  |  52 lines

  1. Newsgroups: comp.arch.embedded,comp.lang.c
  2. Path: in2.uu.net!allegra!ulysses!netnews
  3. From: Phong Vo <kpv@research.att.com>
  4. Subject: Re: Using malloc of C on embedded system?
  5. Sender: netnews@ulysses.homer.att.com (Shankar Ishwar)
  6. Message-ID: <3163E1DB.41C67EA6@research.att.com>
  7. Date: Thu, 4 Apr 1996 14:51:07 GMT
  8. Content-Transfer-Encoding: 7bit
  9. Content-Type: text/plain; charset=us-ascii
  10. References: <4jml7h$cbc@castor.usc.edu> <4jrndq$ate@kuikka.inet.fi> <4jtbot$o1@Mars.mcs.com>
  11. Mime-Version: 1.0
  12. X-Mailer: Mozilla 2.0 (X11; I; SunOS 4.1.2 sun4m)
  13. Organization: AT&T Bell Laboratories
  14.  
  15. John Payson wrote:
  16. > In article <4jrndq$ate@kuikka.inet.fi>,
  17. > Risto Jokinen  <hatrjo@hat-fi.kone.com> wrote:
  18. > >This mechanism works. random size malloc/free does not work on embedded systems, or
  19. > >at least it is impossible to debug, and can be VERY slow. fixed size partition pool
  20. > >manager takes <<50us for malloc/free in any processor. 
  21. > Fixed-size malloc/free is often a good approach if it works; to help it
  22. > along, however, it's often useful to have a "version" of malloc for odd-
  23. > sized blocks that will never be freed (allocate a large memory pool for
  24. > these things and just track the last byte used), and sometimes useful to
  25. > have several memory pools for different-sized objects.
  26. Get my Vmalloc package from http://www.research.att.com/orgs/ssr/book/reuse/.
  27. It allows you to create different regions for allocation based on different
  28. requirements such as special types of memory or special ways to allocate
  29. (fixed size objects, objects never freed, etc.).
  30.  
  31. > As I mentioned in another post, the "binary buddy" system is often a good
  32. > compromise between internal and external fragmentation in embedded systems.
  33. > All objects consist of a power-of-two number number of "atoms" [smallest
  34. > allocatable chunk] and, for simplicity, the "total" number of atoms must
  35. > be a power of two [if the memory size isn't a power of two, "pre-allocate"
  36. > the memory that isn't there].
  37. Before anyone get lulled into this. The binary buddy system is rather wasteful
  38. of memory unless allocated blocks are luckily closed to powers of two. It is 
  39. designed for time speed-up not for space efficiency. Interested people can look
  40. up the Vmalloc paper in the 3/96 issue of SP&E which contains a study on SUN
  41. comparing various malloc implementations using trace data from real programs.
  42. One of the mallocs is based on the binary buddy system. It runs relatively fast
  43. in CPU time but typically wastes about 40% of space. The space wastage causes
  44. it to slow down in some large programs because it ends up spending more system 
  45. time to get raw heap memory. On a time-sharing system with virtual memory,
  46. guess what the effect will be on swap space and overall system performance.
  47. On an embedded system with limited memory, the space wastage can be critical.
  48.